package com.hs.biye.controller.admin;

import com.hs.biye.constant.MessageConstant;
import com.hs.biye.excepction.BaseException;
import com.hs.biye.model.DTO.PatientRequest;
import com.hs.biye.model.VO.PatientVo;
import com.hs.biye.model.reslut.Result;
import com.hs.biye.model.reslut.ResultPage;
import com.hs.biye.service.PatientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@RestController
@RequestMapping("/admin/pat")
@Slf4j
public class PatientController {

    @Resource
    private PatientService patientService;



    @PostMapping("/pages")
    public ResultPage<PatientVo> getPagesPatient(@RequestBody PatientRequest patientRequest){
        if (patientRequest == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        ResultPage<PatientVo> pagePatient = patientService.getPagePatient(patientRequest);
        if (pagePatient == null){
            return ResultPage.faile(MessageConstant.NOT_QUERY);
        }
        return pagePatient;
    }

    @GetMapping("/delete/{id}")
    public Result<Boolean> deletePatient(@PathVariable Integer id){
        if (id== null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        Boolean b = patientService.deletepatient(id);
        return Result.success(b);
    }

}
